﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="frmProyectoRecetaEdicion.aspx.cs" Inherits="WebMenu.Pagina.Proyecto.frmProyectoRecetaEdicion" %>

<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
    <script src="../../style/script/jquery-1.11.2.js"></script>
    <script src="../../style/script/jquery-ui.js"></script>
    <link href="../../style/css/smoothness/theme.css" rel="stylesheet" />
    <link href="../../style/css/smoothness/jquery-ui.css" rel="stylesheet" />

    <style type="text/css">
        /*#region name */
        .ocultar {
            display: none;
        }

        .alinearNumero {
            text-align: right;
        }
        /*#endregion */
    </style>
    <script type="text/javascript">
        $(window).load(function () {

            $('#dialog').dialog({
                autoOpen: false,
                modal: true,
                width: 600,
                heigth: 250,
                title: 'Registro cliente',
                buttons: {
                    'Grabar': function () {
                        if (ValidarRegistroCliente() == '') {
                            document.getElementById("<%=btnGrCliente.ClientID %>").click();
                        }
                        else {
                            alert(ValidarRegistroCliente());
                        }
                    },
                    'Cancelar': function () {
                        $(this).dialog('close');
                    }
                },
                open: function (type, data) {
                    $(this).parent().appendTo('form:first');
                }
            });
        });

        function MostrarPopUp() {
            $('#dialog').dialog('open');
        }

        function CerrarPopUp() {
            $('#dialog').dialog('close');
        }

        function ValidarRegistroCliente() {
            var mensaje = '';

            var listDep = document.getElementById('<%= ddlDepRegistro.ClientID %>');
            var listPro = document.getElementById('<%= ddlProRegistro.ClientID %>');
            var Ruc = $('#<%=txtRUC.ClientID %>').val();

            for (i = 0; i < listDep.length; i++) {
                if ((listDep[i].selected == true) && (listDep[i].value == "-2")) {
                    mensaje = mensaje + "Debe de seleccionar un departamento.\n ";
                }
            }

            for (i = 0; i < listPro.length; i++) {
                if ((listPro[i].selected == true) && (listPro[i].value == "-2")) {
                    mensaje = mensaje + "Debe de seleccionar una provincia.\n ";
                }
            }

            if (Ruc == '') {
                mensaje = mensaje + "Debe de ingresar el ruc del cliente.\n ";
            }
            else {
                var long = Ruc.length;
                if (parseInt(long) < 11) {
                    mensaje = mensaje + "Debe de ingresar el ruc del cliente correctamente.\n ";
                }
            }

            if ($('#<%=txtNombre.ClientID %>').val() == '') {
                mensaje = mensaje + "Debe de ingresar la razón social del cliente.\n ";
            }

            return mensaje;
        }
        function Calculo(valor1, valor2) {
            var NroTabla = valor1;
            var NroFila = valor2;
            var Precio = $("#Text5_" + NroTabla + "_" + NroFila).html();
            var Cant1 = $("#Text2_" + NroTabla + "_" + NroFila).val();
            var Pax = $("#Text3_" + NroTabla + "_" + NroFila).val();
            var Cant = parseFloat(Cant1) * parseFloat(Pax);
            $("#Text4_" + NroTabla + "_" + NroFila).val(parseFloat(Cant));
            var Cant = $("#Text4_" + NroTabla + "_" + NroFila).val();
            var valor00 = parseFloat(Cant) * parseFloat(Precio);
            $("#Text6_" + NroTabla + "_" + NroFila).val(valor00);
            SumaTotal(valor1);
            return true;
        }

        function SumaTotal(NroTabla) {
            var NroFila = $("#<%=hdNroFila.ClientID %>").val();
            var sumaTotal = 0;
            for (i = 0; i < NroFila; i++) {
                sumaTotal = parseFloat(sumaTotal) + parseFloat($("#Text6_" + NroTabla + "_" + i).val());
            }
            $("#Text7_" + NroTabla).val(sumaTotal);
        }

        function isNumeroDecimal(e) {
            if (!(e.keyCode >= 48 && e.keyCode <= 57 || e.keyCode == 46)) {
                e.preventDefault();
                e.returnValue = false;
                return
            }
        }

    </script>
<br><br>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="ddlDepartamento" EventName="SelectedIndexChanged" />
            <asp:AsyncPostBackTrigger ControlID="ddlProvincia" EventName="SelectedIndexChanged" />
            <asp:AsyncPostBackTrigger ControlID="ddlTipo" EventName="SelectedIndexChanged" />
            <asp:AsyncPostBackTrigger ControlID="ddlClase" EventName="SelectedIndexChanged" />
            <asp:AsyncPostBackTrigger ControlID="ddlReceta" EventName="SelectedIndexChanged" />
        </Triggers>
        <ContentTemplate>
            <table>
                <tr>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td></td>
                    <td colspan="5">Proyecto</td>
                    <td></td>
                </tr>
                <tr>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td></td>
                    <td>Deparatamento:</td>
                    <td>
                        <asp:DropDownList ID="ddlDepartamento" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlDepartamento_SelectedIndexChanged">
                        </asp:DropDownList>
                    </td>
                    <td></td>
                    <td>Provincia:</td>
                    <td>
                        <asp:DropDownList ID="ddlProvincia" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlProvincia_SelectedIndexChanged">
                        </asp:DropDownList>
                    </td>
                    <td></td>
                </tr>
                <tr>
                    <td></td>
                    <td>Cliente:</td>
                    <td colspan="4">
                        <asp:DropDownList ID="ddlCliente" runat="server">
                        </asp:DropDownList>
                        <asp:Button ID="btnAddCliente" runat="server" Text="+" OnClick="btnAddCliente_Click" />
                    </td>
                    <td></td>
                </tr>
                <tr>
                    <td></td>
                    <td>Plato para el:</td>
                    <td>
                        <asp:DropDownList ID="ddlTipo" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlTipo_SelectedIndexChanged">
                        </asp:DropDownList>
                    </td>
                    <td></td>
                    <td>Clase de Plato:</td>
                    <td>
                        <asp:DropDownList ID="ddlClase" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlClase_SelectedIndexChanged">
                        </asp:DropDownList>
                    </td>
                    <td></td>
                </tr>
                <tr>
                    <td></td>
                    <td>Receta:</td>
                    <td colspan="4">
                        <asp:DropDownList ID="ddlReceta" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlReceta_SelectedIndexChanged">
                        </asp:DropDownList>
                    </td>
                    <td></td>
                </tr>
                <tr>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td></td>
                    <td colspan="4">
                        <asp:HiddenField ID="hdIdProv" runat="server" Value="0" />
                        <asp:HiddenField ID="hdIdPrecio" runat="server" Value="0" />
                        <asp:HiddenField ID="hdPrecio" runat="server" Value="0.00" />
                        <asp:HiddenField ID="hdIDProy" runat="server" Value="0" />
                        <asp:HiddenField ID="hdIDReceta" runat="server" Value="0" />
                        <asp:HiddenField ID="hdIDCliente" runat="server" Value="0" />
                        <asp:GridView ID="gvProducto" runat="server" AutoGenerateColumns="False" OnRowDataBound="gvProducto_RowDataBound">
                            <Columns>
                                <asp:BoundField DataField="ID_TPROD" HeaderStyle-CssClass="ocultar" HeaderText="IdTipoProd" ItemStyle-CssClass="ocultar">
                                    <HeaderStyle CssClass="ocultar" />
                                    <ItemStyle CssClass="ocultar" />
                                </asp:BoundField>
                                <asp:BoundField DataField="ID_PRODUCTO" HeaderStyle-CssClass="ocultar" HeaderText="IdProd" ItemStyle-CssClass="ocultar">
                                    <HeaderStyle CssClass="ocultar" />
                                    <ItemStyle CssClass="ocultar" />
                                </asp:BoundField>
                                <asp:BoundField HeaderText="ID_PROVEEDOR" DataField="ID_PROVEEDOR" HeaderStyle-CssClass="ocultar" ItemStyle-CssClass="ocultar">
                                    <HeaderStyle CssClass="ocultar" />
                                    <ItemStyle CssClass="ocultar" />
                                </asp:BoundField>
                                <asp:BoundField HeaderText="ID_PRECIO" DataField="ID_PRECIO" HeaderStyle-CssClass="ocultar" ItemStyle-CssClass="ocultar">
                                    <HeaderStyle CssClass="ocultar" />
                                    <ItemStyle CssClass="ocultar" />
                                </asp:BoundField>
                                <asp:BoundField DataField="DESC_TPROD" HeaderText="Tipo Producto" HeaderStyle-CssClass="ocultar" ItemStyle-CssClass="ocultar">
                                    <HeaderStyle CssClass="ocultar" />
                                    <ItemStyle CssClass="ocultar" />
                                </asp:BoundField>
                                <asp:BoundField DataField="NOM_PROD" HeaderText="Ingrediente" />
                                <asp:TemplateField HeaderText="Proveedor">
                                    <ItemTemplate>
                                        <asp:DropDownList ID="ddlProveedor" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlProveedor_SelectedIndexChanged"></asp:DropDownList>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:BoundField HeaderText="PRECIO" DataField="PRECIO_CIGV" ItemStyle-CssClass="alinearNumero" />
                                <asp:BoundField DataField="ID_PROY_REC_ING" HeaderText="ID_PROY_REC_ING" HeaderStyle-CssClass="ocultar" ItemStyle-CssClass="ocultar">
                                    <HeaderStyle CssClass="ocultar" />
                                    <ItemStyle CssClass="ocultar" />
                                </asp:BoundField>
                            </Columns>
                        </asp:GridView>
                        </td>
                    <td style="vertical-align:top">
                        <asp:Button ID="btnProyecto" runat="server"  Text="Grabar" OnClick="btnProyecto_Click" />
                    </td>
                        
                    </td>
                    <td></td>
                </tr>
                <tr>
                    <td></td>
                    <td>                        
                        <asp:HiddenField ID="hdNroFila" runat="server" />
                    </td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td></td>
                    <td colspan="5">
                        <asp:Label ID="lbTbCosto" runat="server" Text=""></asp:Label>
                    </td>
                    <td></td>
                </tr>
                <tr>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
            </table>
        </ContentTemplate>
    </asp:UpdatePanel>
    <div id="dialog">
        <asp:UpdatePanel ID="udpRegistro" runat="server">
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="ddlDepRegistro" EventName="SelectedIndexChanged" />
                <asp:AsyncPostBackTrigger ControlID="btnGrCliente" EventName="Click" />
            </Triggers>
            <ContentTemplate>
                <%--<asp:HiddenField ID="hdIDCliente" runat="server" Value="0" />--%>
                <table>
                    <tr>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                    </tr>
                    <tr>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                    </tr>
                    <tr>
                        <td></td>
                        <td>Departamento:</td>
                        <td>
                            <asp:DropDownList ID="ddlDepRegistro" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlDepRegistro_SelectedIndexChanged">
                            </asp:DropDownList>
                        </td>
                        <td></td>
                        <td>Provincia</td>
                        <td>
                            <asp:DropDownList ID="ddlProRegistro" runat="server">
                            </asp:DropDownList>
                        </td>
                        <td></td>
                    </tr>
                    <tr>
                        <td></td>
                        <td>RUC</td>
                        <td colspan="4">
                            <asp:TextBox ID="txtRUC" runat="server" MaxLength="11" Width="135" onkeypress="javascript:return isNumeroDecimal(event);"></asp:TextBox>
                        </td>
                        <td></td>
                    </tr>
                    <tr>
                        <td></td>
                        <td>Razón social:</td>
                        <td colspan="4">
                            <asp:TextBox ID="txtNombre" runat="server" MaxLength="150" Width="100%"></asp:TextBox>
                        </td>
                        <td></td>
                    </tr>
                    <tr>
                        <td></td>
                        <td colspan="5">
                            <asp:Button ID="btnGrCliente" runat="server" Text="Grabar" Style="display: none" OnClick="btnGrCliente_Click" />

                        </td>
                        <td></td>
                    </tr>
                    <tr>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                    </tr>
                </table>
            </ContentTemplate>
        </asp:UpdatePanel>

    </div>
</asp:Content>
